package cn.rkylin.oms.aftersale.resend.controller;

import java.math.BigDecimal;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;

import cn.rkylin.core.controller.ApolloController;
import cn.rkylin.oms.aftersale.resend.dao.IAfterSaleResendDAO;
import cn.rkylin.oms.aftersale.resend.dao.IAfterSaleResendSkuDAO;
import cn.rkylin.oms.aftersale.resend.domain.AfterSaleResend;
import cn.rkylin.oms.aftersale.resend.domain.AfterSaleResendSku;
import cn.rkylin.oms.aftersale.resend.service.IAfterSaleResendService;
import cn.rkylin.oms.aftersale.resend.vo.ResendVO;
import cn.rkylin.oms.common.annotation.SystemControllerLog;
import cn.rkylin.oms.common.consts.YesNoConst;
import cn.rkylin.oms.common.context.CurrentUser;
import cn.rkylin.oms.common.context.WebContextFactory;
import cn.rkylin.oms.goods.service.IGoodsService;
import cn.rkylin.oms.goods.service.IPrjSkuService;
import cn.rkylin.oms.goods.vo.PrjSkuVO;
import cn.rkylin.oms.order.service.IOrderService;
import cn.rkylin.oms.order.vo.OrderSkuVO;

/**
 * 类名:AfterSaleResendController <br/>
 * 作用: 补发单操作Controller. <br/>
 * 创建原因: 对外提供补发单相关操作. <br/>
 * 创建时间: 2017年11月7日 9:20:00 <br/>
 * 
 * @author liPeng
 * @see
 */
@Controller
@RequestMapping("/afterSaleResend")
public class AfterSaleResendController extends ApolloController {

    private static final Log logger = LogFactory.getLog(AfterSaleResendController.class);

    /**
     * resendService:补发单服务层
     */
    @Autowired
    public IAfterSaleResendService resendService;

    /**
     * resendService:补发单数据层
     */
    @Autowired
    public IAfterSaleResendDAO resendDao;

    /**
     * orderService: 订单服务层
     */
    @Autowired
    public IOrderService orderService;

    /**
     * goodsService: 商品服务层
     */
    @Autowired
    public IGoodsService goodsService;

    /**
     * resendSkuDao:补发单明细数据层
     */
    @Autowired
    public IAfterSaleResendSkuDAO resendSkuDao;

    /**
     * prjSkuService：系统商品服务层
     */
    @Autowired
    public IPrjSkuService prjSkuService;

    /**
     * 待审核
     *
     * @param quickSearch
     *            快速查询条件
     * @param formJson
     *            高级检索条件
     * @return 返回值JSON格式字符串
     * @Param start 第几页
     * @Param length 每页多少行
     */
    @ResponseBody
    @RequestMapping(value = "/getWaitVerifyTable")
    public Map<String, Object> getWaitVerifyTable(String quickSearch, @RequestParam(required = false, defaultValue = "0") int start,
            @RequestParam(required = false, defaultValue = "10") int length, String formJson) throws Exception {

        // 状态
        String status = "a";
        // 取消状态
        String cancelStatus = "n";
        return getResendList(quickSearch, formJson, status, cancelStatus, start, length);
    }

    /**
     * 待发货
     *
     * @param quickSearch
     *            快速查询条件
     * @param formJson
     *            高级检索条件
     * @return 返回值JSON格式字符串
     * @Param start 第几页
     * @Param length 每页多少行
     */
    @ResponseBody
    @RequestMapping(value = "/getWaitDeliverTable")
    public Map<String, Object> getWaitDeliverTable(String quickSearch, @RequestParam(required = false, defaultValue = "0") int start,
            @RequestParam(required = false, defaultValue = "10") int length, String formJson) throws Exception {
        // 状态
        String status = "f";
        // 取消状态
        String cancelStatus = "n";
        return getResendList(quickSearch, formJson, status, cancelStatus, start, length);
    }

    /**
     * 已完成
     *
     * @param quickSearch
     *            快速查询条件
     * @param formJson
     *            高级检索条件
     * @return 返回值JSON格式字符串
     * @Param start 第几页
     * @Param length 每页多少行
     */
    @ResponseBody
    @RequestMapping(value = "/getCompleteTable")
    public Map<String, Object> getCompleteTable(String quickSearch, @RequestParam(required = false, defaultValue = "0") int start,
            @RequestParam(required = false, defaultValue = "10") int length, String formJson) throws Exception {
        // 状态
        String status = "z";
        // 取消状态
        String cancelStatus = "n";
        return getResendList(quickSearch, formJson, status, cancelStatus, start, length);
    }

    /**
     * 已取消
     *
     * @param quickSearch
     *            快速查询条件
     * @param formJson
     *            高级检索条件
     * @return 返回值JSON格式字符串
     * @Param start 第几页
     * @Param length 每页多少行
     */
    @ResponseBody
    @RequestMapping(value = "/getCancalTable")
    public Map<String, Object> getCancalTable(String quickSearch, @RequestParam(required = false, defaultValue = "0") int start,
            @RequestParam(required = false, defaultValue = "10") int length, String formJson) throws Exception {
        // 状态
        String status = "";
        // 取消状态
        String cancelStatus = "y";
        return getResendList(quickSearch, formJson, status, cancelStatus, start, length);
    }

    /**
     * 根据不同的需求返回列表数据
     * 
     * @param quickSearch
     * @param type
     * @param start
     * @param length
     * @return
     * @throws Exception
     */
    private Map<String, Object> getResendList(String quickSearch, String formJson, String status, String cancelStatus, int start, int length)
            throws Exception {
        logger.info("查询补发单：/afterSaleResend/resendList");
        ResendVO queryParamVO = new ResendVO();

        // 设置补发单状态
        queryParamVO.setResendStatus(status);
        // 设置补发单取消状态
        queryParamVO.setCancelStatus(cancelStatus);

        // 获取当前登录人
        CurrentUser currentUser = WebContextFactory.getWebContext().getCurrentUser();
        if (currentUser == null) {
            return getFailedMap("查询当前登录人失败");
        }
        // 获取当前登录人所属项目
        String projectId = currentUser.getCurrentProject().getPrjId();
        if (StringUtils.isBlank(projectId)) {
            return getFailedMap("查询当前登录人所属项目失败");
        }
        // 设置项目id
        queryParamVO.setPrjId(projectId);

        if (quickSearch != null && StringUtils.isNotEmpty(quickSearch)) {
            quickSearch = URLDecoder.decode(quickSearch, "UTF-8");
            if (StringUtils.isNotEmpty(quickSearch)) {
                queryParamVO.setQuickSearch(quickSearch.trim());
            }
        }
        if (formJson != null && StringUtils.isNotEmpty(formJson)) {
            formJson = URLDecoder.decode(formJson, "UTF-8");
            Map<String, String> mapItem = JSONObject.parseObject(formJson, Map.class);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            if (mapItem != null && !mapItem.isEmpty()) {
                if (StringUtils.isNotEmpty(mapItem.get("queryOrderCode"))) {
                    queryParamVO.setQueryOrderCode(mapItem.get("queryOrderCode"));
                }
                if (StringUtils.isNotEmpty(mapItem.get("queryShopName"))) {
                    queryParamVO.setQueryShopName(mapItem.get("queryShopName"));
                }
                if (StringUtils.isNotEmpty(mapItem.get("queryStorName"))) {
                    queryParamVO.setQueryStorName(mapItem.get("queryStorName"));
                }
                if (StringUtils.isNotEmpty(mapItem.get("queryLgstName"))) {
                    queryParamVO.setQueryLgstName(mapItem.get("queryLgstName"));
                }
                if (StringUtils.isNotEmpty(mapItem.get("queryDateType"))) {
                    queryParamVO.setQueryDateType(mapItem.get("queryDateType"));
                }
                if (StringUtils.isNotEmpty(mapItem.get("queryDateStart"))) {
                    queryParamVO.setQueryDateStart(sdf.parse(mapItem.get("queryDateStart")));
                }
                if (StringUtils.isNotEmpty(mapItem.get("queryDateEnd"))) {
                    queryParamVO.setQueryDateEnd(sdf.parse(mapItem.get("queryDateEnd")));
                }
            }

        }

        Map<String, String> replaceFieldsMap = new HashMap<String, String>();

        // 排序语句生成
        String orderStatement = getOrderString(IAfterSaleResendDAO.class.getName(), "pageSelectResendByCondition", replaceFieldsMap);
        if (StringUtils.isNotEmpty(orderStatement)) {
            queryParamVO.setOrderBy(orderStatement);
        }
        // 处理分页信息
        if (length == -1) {
            length = Integer.MAX_VALUE;
        }
        int page = start / length + 1;

        // 执行查询
        PageInfo<ResendVO> ruleVOList = resendService.getResendListByCondition(page, length, queryParamVO);

        Map<String, Object> returnMap = new HashMap<>();
        if (null != ruleVOList) {
            returnMap = getSuccessMap("查询补发单数据成功");
            returnMap.put(RECORDS_FILTERED, ruleVOList.getTotal());
            returnMap.put(RECORDS_TOTAL, ruleVOList.getTotal());
            returnMap.put(RETURN_DATA, ruleVOList.getList());
        } else {
            returnMap = getFailedMap("查询补发单数据失败");
        }
        logger.info("查询补发单调用结束");
        return returnMap;
    }

    /**
     * queryStateCount：查询补发单列表数量
     * 
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/queryStateCount")
    public Map<String, Object> queryStateCount(String quickSearch, String formJson) throws Exception {
        logger.info("查询补发单状态数据：/afterSaleResend/queryStateCount");
        // 用于返回值的json对象
        Map<String, Object> returnMap = new HashMap<String, Object>();
        try {
            // 查询条件
            ResendVO queryParamVO = new ResendVO();
            // 获取当前登录人
            CurrentUser currentUser = WebContextFactory.getWebContext().getCurrentUser();
            if (currentUser == null) {
                return getFailedMap("查询当前登录人失败");
            }
            // 获取当前登录人所属项目
            String projectId = currentUser.getCurrentProject().getPrjId();
            if (StringUtils.isBlank(projectId)) {
                return getFailedMap("查询当前登录人所属项目失败");
            }
            // 设置项目id
            queryParamVO.setPrjId(projectId);
            // 快速查询
            if (quickSearch != null && StringUtils.isNotEmpty(quickSearch)) {
                quickSearch = URLDecoder.decode(quickSearch, "UTF-8");
                if (StringUtils.isNotEmpty(quickSearch)) {
                    queryParamVO.setQuickSearch(quickSearch);
                }
            }
            // 高级查询检索条件
            if (formJson != null && StringUtils.isNotEmpty(formJson)) {
                formJson = URLDecoder.decode(formJson, "UTF-8");
                Map<String, String> mapItem = JSONObject.parseObject(formJson, Map.class);
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
                if (mapItem != null && !mapItem.isEmpty()) {
                    if (StringUtils.isNotEmpty(mapItem.get("queryOrderCode"))) {
                        queryParamVO.setQueryOrderCode(mapItem.get("queryOrderCode"));
                    }
                    if (StringUtils.isNotEmpty(mapItem.get("queryShopName"))) {
                        queryParamVO.setQueryShopName(mapItem.get("queryShopName"));
                    }
                    if (StringUtils.isNotEmpty(mapItem.get("queryStorName"))) {
                        queryParamVO.setQueryStorName(mapItem.get("queryStorName"));
                    }
                    if (StringUtils.isNotEmpty(mapItem.get("queryLgstName"))) {
                        queryParamVO.setQueryLgstName(mapItem.get("queryLgstName"));
                    }
                    if (StringUtils.isNotEmpty(mapItem.get("queryDateType"))) {
                        queryParamVO.setQueryDateType(mapItem.get("queryDateType"));
                    }
                    if (StringUtils.isNotEmpty(mapItem.get("queryDateStart"))) {
                        queryParamVO.setQueryDateStart(sdf.parse(mapItem.get("queryDateStart")));
                    }
                    if (StringUtils.isNotEmpty(mapItem.get("queryDateEnd"))) {
                        queryParamVO.setQueryDateEnd(sdf.parse(mapItem.get("queryDateEnd")));
                    }
                }

            }
            // 执行查询
            List<ResendVO> list = resendService.findCounts(queryParamVO);
            // 设置返回结果内容
            returnMap.put(JSON_RESULT, SUCCESS);
            int countVerify = 0;
            int countDeliver = 0;
            int countComplete = 0;
            int countCancal = 0;

            if (list != null && list.size() > 0) {
                countVerify = list.get(0).getCountVerify() != null ? list.get(0).getCountVerify().intValue() : 0;
                countDeliver = list.get(0).getCountDeliver() != null ? list.get(0).getCountDeliver().intValue() : 0;
                countComplete = list.get(0).getCountComplete() != null ? list.get(0).getCountComplete().intValue() : 0;
                countCancal = list.get(0).getCountCancal() != null ? list.get(0).getCountCancal().intValue() : 0;
            }
            returnMap.put("countVerify", countVerify);
            returnMap.put("countDeliver", countDeliver);
            returnMap.put("countComplete", countComplete);
            returnMap.put("countCancal", countCancal);
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
            returnMap.put(JSON_RESULT, FAILED);
            returnMap.put(JSON_MSG, ex.getMessage());
        }
        // 生成返回结果json串，null内容也需要返回
        return returnMap;
    }

    /**
     * 根据补发id获取补发单
     * 
     * @param resendId
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getResendById")
    public Map<String, Object> getResendById(@RequestParam(value = "resendId") String resendId) {
        logger.info(String.format("获取补发单明细：/afterSaleResend/resendFullDetail/%s", resendId));
        // 用于返回值的json对象
        Map<String, Object> returnMap = new HashMap<String, Object>();
        try {
            ResendVO result = resendService.getResendDetailById(resendId);
            if (null != result) {
                returnMap = getSuccessMap("系统调用完成");
                returnMap.put(RETURN_DATA, result);
            }
        } catch (Exception e) {
            logger.error(e.getMessage());
            returnMap = getFailedMap(e.getMessage());
        }
        return returnMap;
    }

    /**
     * cancelResend：取消补发单
     * 
     * @param resendVO
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/cancelResend")
    @SystemControllerLog(module = "系统补发单", operation = "取消补发单", keyCode = "resendId")
    public Map<String, Object> cancelResend(@RequestParam(value = "resendId") String resendId) {
        logger.info(String.format("获取补发单明细：/afterSaleResend/cancelResend/%s", resendId));
        // 用于返回值的json对象
        Map<String, Object> returnMap = new HashMap<String, Object>();

        try {

            // 根据补发单id查询补发单
            ResendVO result = resendService.getResendDetailById(resendId);
            // 对补发单做取消操作
            String returnMsg = resendService.cancelResend(result);
            if ("取消成功".equals(returnMsg)) {
                returnMap.put(JSON_RESULT, SUCCESS);
                returnMap.put(RETURN_DATA, returnMsg);
            } else {
                returnMap.put(JSON_RESULT, FAILED);
                returnMap.put(JSON_MSG, returnMsg);
            }

        } catch (Exception ex) {

            logger.error(ex.getMessage(), ex);
            returnMap.put(JSON_RESULT, FAILED);
            returnMap.put(JSON_MSG, ex.getMessage());
        }
        returnMap.put("resendId", resendId);
        return returnMap;
    }

    /**
     * saveResend：保存补发单及其明细
     * 
     * @param orderSkuIds
     * @param resendVO
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/saveResend")
    @SystemControllerLog(module = "系统补发单", operation = "保存补发单及其明细", keyCode = "resendId")
    public Map<String, Object> saveResend(@RequestBody ResendVO resendVO) {
        logger.info("保存补发单：/afterSaleResend/saveResend");
        // 用于返回值的json对象
        Map<String, Object> returnMap = new HashMap<String, Object>();
        try {
            String returnMsg = resendService.saveResends(resendVO);
            if ("添加成功".equals(returnMsg)) {
                returnMap.put(JSON_RESULT, SUCCESS);
                returnMap.put(RETURN_DATA, returnMsg);
            } else if ("修改成功".equals(returnMsg)) {
                returnMap.put(JSON_RESULT, SUCCESS);
                returnMap.put(RETURN_DATA, returnMsg);
            } else if ("请至少添加有一条商品信息".equals(returnMsg)) {
                returnMap.put(JSON_RESULT, FAILED);
                returnMap.put(JSON_MSG, returnMsg);
            } else if ("补发单数量不能为0".equals(returnMsg)) {
                returnMap.put(JSON_RESULT, FAILED);
                returnMap.put(JSON_MSG, returnMsg);
            }
        } catch (Exception e) {
            logger.error(e.getMessage());
            returnMap.put(JSON_RESULT, FAILED);
            returnMap = getFailedMap(e.getMessage());
        }
        returnMap.put("resendId", resendVO.getResendId());
        return returnMap;
    }

    /**
     * auditResend：审核补发单
     * 
     * @param resendIdList
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value = "/auditResend", method = RequestMethod.POST)
    @SystemControllerLog(module = "系统补发单", operation = "审核补发单", keyCode = "resendId")
    public Map<String, Object> auditResend(@RequestBody ArrayList<String> resendIdList) throws Exception {
        // 用于返回值的json对象
        Map<String, Object> returnJSON = new HashMap<String, Object>();
        try {
            returnJSON = resendService.auditResend(resendIdList);
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
            returnJSON.put(JSON_RESULT, FAILED);
            returnJSON.put(JSON_MSG, ex.getMessage());
        }
        returnJSON.put("resendId", resendIdList);
        return returnJSON;
    }

    /**
     * mandatoryAuditResend：强制审核补发单
     * 
     * @param resendIdList
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/mandatoryAuditResend")
    @SystemControllerLog(module = "系统补发单", operation = "强制审核补发单", keyCode = "resendId")
    public Map<String, Object> mandatoryAuditResend(String resendIds, String question) {
        // 用于返回值的json对象
        Map<String, Object> returnJSON = new HashMap<String, Object>();
        try {
            if ("1".equals(question)) {
                Map<String, String> serviceMap = resendService.checkResends(resendIds);
                // 当校验以后补发单中不存在非订单商品或者补发商品数量大于订单数量,直接审核
                if (StringUtils.isBlank(serviceMap.get(RETURN_DATA))) {
                    Map<String, Object> serviceMaps = resendService.mandatoryAuditResend(resendIds);
                    returnJSON.put(JSON_RESULT, serviceMaps.get(JSON_RESULT));
                    returnJSON.put(RETURN_DATA, serviceMaps.get(RETURN_DATA));
                    returnJSON.put(JSON_MSG, serviceMaps.get(JSON_MSG));
                } else {
                    returnJSON.put(RETURN_DATA, serviceMap.get(RETURN_DATA));
                    returnJSON.put(JSON_RESULT, serviceMap.get(JSON_RESULT));
                    returnJSON.put(JSON_MSG, serviceMap.get(JSON_MSG));
                    returnJSON.put("question", serviceMap.get(JSON_MSG));
                }
            } else {
                Map<String, Object> serviceMap = resendService.mandatoryAuditResend(resendIds);
                returnJSON.put(JSON_RESULT, serviceMap.get(JSON_RESULT));
                returnJSON.put(RETURN_DATA, serviceMap.get(RETURN_DATA));
                returnJSON.put(JSON_MSG, serviceMap.get(JSON_MSG));
            }

        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
            returnJSON.put(JSON_RESULT, FAILED);
            returnJSON.put(JSON_MSG, ex.getMessage());
        }
        returnJSON.put("resendId", resendIds);
        return returnJSON;
    }

    /**
     * 根据补发单id获取补发单明细
     * 
     * @param resendId
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/resendDetail")
    public Map<String, Object> resendDetail(@RequestParam(value = "resendId") String resendId) {
        logger.info(String.format("系统调用获取补发单明细：/afterSaleResend/resendDetail/%s", resendId));
        // 用于返回值的json对象
        Map<String, Object> returnMap = new HashMap<String, Object>();
        try {
            List<AfterSaleResendSku> resendSkus = resendService.getResendSku(resendId);
            if (null != resendSkus) {
                returnMap = getSuccessMap("查询补发单明细数据成功");
                returnMap.put(RETURN_DATA, resendSkus);
            }
        } catch (Exception e) {
            logger.error(e.getMessage());
            returnMap = getFailedMap(e.getMessage());
        }
        return returnMap;
    }

    /**
     * deleteResend：删除补发单
     * 
     * @param message
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/deleteResend")
    @SystemControllerLog(module = "系统补发单", operation = "删除补发单", keyCode = "resendId")
    public Map<String, Object> deleteResend(@RequestParam(value = "resendIds") String resendIds) {
        logger.info(String.format("删除补发单：/afterSaleResend/deleteResend/%s", resendIds));
        // 用于返回值的json对象
        Map<String, Object> returnMap = new HashMap<String, Object>();
        try {
            String returnMsg = resendService.deleteResendbyID(resendIds);
            if ("删除成功".equals(returnMsg)) {
                returnMap.put(RETURN_DATA, returnMsg);
                returnMap = getSuccessMap("删除成功");
            }
        } catch (Exception e) {
            logger.error(e.getMessage());
            returnMap = getFailedMap(e.getMessage());
        }
        returnMap.put("resendId", resendIds);
        return returnMap;
    }

    /**
     * 获取 订单和订单关联的补发单 商品信息
     *
     * @param orderId
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getOrderSkuById")
    public Map<String, Object> getOrderSkuById(String orderId) {
        Map<String, Object> returnMap = new HashMap<>();
        try {
            List<OrderSkuVO> orderSkuList = orderService.getOrderSkuAndResendSkuByOrderId(orderId);
            if (orderSkuList != null && orderSkuList.size() > 0) {
                // 将 isGift 的"是"/"否" 转换为 "y"/"n"
                for (int i = 0; i < orderSkuList.size(); i++) {
                    if ("是".equals(orderSkuList.get(i).getIsGift())) {
                        orderSkuList.get(i).setIsGift(YesNoConst.YES);
                    } else {
                        orderSkuList.get(i).setIsGift(YesNoConst.NO);
                    }
                }
                // 通过 divideOrderFee 给 divideGoodsFee 赋值
                for (int i = 0; i < orderSkuList.size(); i++) {
                    orderSkuList.get(i).setDivideGoodsFee(orderSkuList.get(i).getDivideOrderFee()
                            .divide(BigDecimal.valueOf(orderSkuList.get(i).getQty()), 2, BigDecimal.ROUND_HALF_UP));
                }
                returnMap = getSuccessMap("系统调用完成");
                returnMap.put(RETURN_DATA, orderSkuList);
            } else {
                returnMap = getSuccessMap("系统调用完成");
                returnMap.put(RETURN_DATA, orderSkuList);
            }

        } catch (Exception e) {
            logger.error(e.getMessage());
            returnMap = getFailedMap(e.getMessage());
        }
        return returnMap;
    }

    /**
     * getPrjSkuList：获取非订单商品列表
     * 
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getPrjSkuList")
    public Map<String, Object> getPrjSkuList() {
        logger.info(String.format("系统调用获取非订单商品列表：/afterSaleResend/getPrjSkuList"));
        // 用于返回值的json对象
        Map<String, Object> returnMap = new HashMap<String, Object>();
        try {
            PrjSkuVO prjSkuVO = new PrjSkuVO();
            // 获取当前登录人
            CurrentUser currentUser = WebContextFactory.getWebContext().getCurrentUser();
            // 获取当前登录人所属项目
            String projectId = currentUser.getCurrentProject().getPrjId();
            prjSkuVO.setPrjId(projectId);

            List<PrjSkuVO> prjSkuVOList = prjSkuService.getGoodsSku(prjSkuVO);
            // 通过 goodsType 给 isGift 赋值
            for (int i = 0; i < prjSkuVOList.size(); i++) {
                if ("赠".equals(prjSkuVOList.get(i).getGoodsType())) {
                    prjSkuVOList.get(i).setIsGift(YesNoConst.YES);
                } else {
                    prjSkuVOList.get(i).setIsGift(YesNoConst.NO);
                }
            }
            returnMap.put(JSON_RESULT, SUCCESS);
            returnMap.put(RETURN_DATA, prjSkuVOList);
        } catch (Exception e) {
            logger.error(e.getMessage());
            returnMap.put(JSON_RESULT, FAILED);
            returnMap.put(JSON_MSG, e.getMessage());
            returnMap = getFailedMap(e.getMessage());
        }
        return returnMap;
    }

    private Map<String, Object> getSuccessMap(String message) {
        Map<String, Object> returnMap = new HashMap<String, Object>();
        returnMap.put(JSON_RESULT, SUCCESS);
        returnMap.put(JSON_MSG, message);
        return returnMap;
    };

    private Map<String, Object> getFailedMap(String message) {
        Map<String, Object> returnMap = new HashMap<String, Object>();
        returnMap.put(JSON_RESULT, FAILED);
        returnMap.put(JSON_MSG, message);
        return returnMap;
    };

    @ResponseBody
    @RequestMapping(value = "/getResendByOrderId")
    public Map<String, Object> getResendByOrderId(@RequestParam(value = "orderId") String orderId) {
        // 用于返回值的json对象
        Map<String, Object> returnMap = null;
        try {
            List<AfterSaleResend> resendList = resendService.findResendByOrderId(orderId);
            if (resendList.size() > 0) {
                returnMap = getSuccessMap("系统调用完成");
                returnMap.put(RETURN_DATA, resendList);
            } else {
                returnMap = getFailedMap("系统调用完成,未获取到数据");
            }
        } catch (Exception e) {
            logger.error(e.getMessage());
            returnMap = getFailedMap(e.getMessage());
        }
        return returnMap;
    }

}